﻿USE [tippelde]
GO
/****** Object:  ForeignKey [FK_dbo.BetResults_dbo.Events_Event_Id]    Script Date: 11/11/2013 18:52:38 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.BetResults_dbo.Events_Event_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[BetResults]'))
ALTER TABLE [dbo].[BetResults] DROP CONSTRAINT [FK_dbo.BetResults_dbo.Events_Event_Id]
GO
/****** Object:  ForeignKey [FK_dbo.BetResults_dbo.Users_User_Id]    Script Date: 11/11/2013 18:52:38 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.BetResults_dbo.Users_User_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[BetResults]'))
ALTER TABLE [dbo].[BetResults] DROP CONSTRAINT [FK_dbo.BetResults_dbo.Users_User_Id]
GO
/****** Object:  ForeignKey [FK_dbo.Bets_dbo.BetResults_BetResult_Id]    Script Date: 11/11/2013 18:52:39 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.Bets_dbo.BetResults_BetResult_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[Bets]'))
ALTER TABLE [dbo].[Bets] DROP CONSTRAINT [FK_dbo.Bets_dbo.BetResults_BetResult_Id]
GO
/****** Object:  ForeignKey [FK_dbo.Bets_dbo.Events_Event_Id]    Script Date: 11/11/2013 18:52:39 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.Bets_dbo.Events_Event_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[Bets]'))
ALTER TABLE [dbo].[Bets] DROP CONSTRAINT [FK_dbo.Bets_dbo.Events_Event_Id]
GO
/****** Object:  ForeignKey [FK_dbo.Bets_dbo.Users_User_Id]    Script Date: 11/11/2013 18:52:39 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.Bets_dbo.Users_User_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[Bets]'))
ALTER TABLE [dbo].[Bets] DROP CONSTRAINT [FK_dbo.Bets_dbo.Users_User_Id]
GO
/****** Object:  ForeignKey [FK_dbo.EventDescriptors_dbo.Events_Id]    Script Date: 11/11/2013 18:52:39 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.EventDescriptors_dbo.Events_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[EventDescriptors]'))
ALTER TABLE [dbo].[EventDescriptors] DROP CONSTRAINT [FK_dbo.EventDescriptors_dbo.Events_Id]
GO
/****** Object:  ForeignKey [FK_dbo.EventDescriptors_dbo.Teams_AwayTeam_Id]    Script Date: 11/11/2013 18:52:39 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.EventDescriptors_dbo.Teams_AwayTeam_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[EventDescriptors]'))
ALTER TABLE [dbo].[EventDescriptors] DROP CONSTRAINT [FK_dbo.EventDescriptors_dbo.Teams_AwayTeam_Id]
GO
/****** Object:  ForeignKey [FK_dbo.EventDescriptors_dbo.Teams_HomeTeam_Id]    Script Date: 11/11/2013 18:52:39 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.EventDescriptors_dbo.Teams_HomeTeam_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[EventDescriptors]'))
ALTER TABLE [dbo].[EventDescriptors] DROP CONSTRAINT [FK_dbo.EventDescriptors_dbo.Teams_HomeTeam_Id]
GO
/****** Object:  ForeignKey [FK_dbo.EventDescriptors_dbo.Teams_Team_Id]    Script Date: 11/11/2013 18:52:39 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.EventDescriptors_dbo.Teams_Team_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[EventDescriptors]'))
ALTER TABLE [dbo].[EventDescriptors] DROP CONSTRAINT [FK_dbo.EventDescriptors_dbo.Teams_Team_Id]
GO
/****** Object:  ForeignKey [FK_dbo.EventDescriptors_dbo.Teams_Team_Id1]    Script Date: 11/11/2013 18:52:39 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.EventDescriptors_dbo.Teams_Team_Id1]') AND parent_object_id = OBJECT_ID(N'[dbo].[EventDescriptors]'))
ALTER TABLE [dbo].[EventDescriptors] DROP CONSTRAINT [FK_dbo.EventDescriptors_dbo.Teams_Team_Id1]
GO
/****** Object:  ForeignKey [FK_dbo.Events_dbo.Users_Creator_Id]    Script Date: 11/11/2013 18:52:39 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.Events_dbo.Users_Creator_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[Events]'))
ALTER TABLE [dbo].[Events] DROP CONSTRAINT [FK_dbo.Events_dbo.Users_Creator_Id]
GO
/****** Object:  ForeignKey [FK_dbo.GroupEvents_dbo.Events_Event_Id]    Script Date: 11/11/2013 18:52:39 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.GroupEvents_dbo.Events_Event_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[GroupEvents]'))
ALTER TABLE [dbo].[GroupEvents] DROP CONSTRAINT [FK_dbo.GroupEvents_dbo.Events_Event_Id]
GO
/****** Object:  ForeignKey [FK_dbo.GroupEvents_dbo.Groups_Group_Id]    Script Date: 11/11/2013 18:52:39 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.GroupEvents_dbo.Groups_Group_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[GroupEvents]'))
ALTER TABLE [dbo].[GroupEvents] DROP CONSTRAINT [FK_dbo.GroupEvents_dbo.Groups_Group_Id]
GO
/****** Object:  ForeignKey [FK_dbo.Groups_dbo.Users_Creator_Id]    Script Date: 11/11/2013 18:52:39 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.Groups_dbo.Users_Creator_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[Groups]'))
ALTER TABLE [dbo].[Groups] DROP CONSTRAINT [FK_dbo.Groups_dbo.Users_Creator_Id]
GO
/****** Object:  ForeignKey [FK_dbo.Logs_dbo.Users_User_Id]    Script Date: 11/11/2013 18:52:39 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.Logs_dbo.Users_User_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[Logs]'))
ALTER TABLE [dbo].[Logs] DROP CONSTRAINT [FK_dbo.Logs_dbo.Users_User_Id]
GO
/****** Object:  ForeignKey [FK_dbo.Results_dbo.Events_Id]    Script Date: 11/11/2013 18:52:39 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.Results_dbo.Events_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[Results]'))
ALTER TABLE [dbo].[Results] DROP CONSTRAINT [FK_dbo.Results_dbo.Events_Id]
GO
/****** Object:  ForeignKey [FK_dbo.UserClaims_dbo.Users_User_Id]    Script Date: 11/11/2013 18:52:39 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.UserClaims_dbo.Users_User_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[UserClaims]'))
ALTER TABLE [dbo].[UserClaims] DROP CONSTRAINT [FK_dbo.UserClaims_dbo.Users_User_Id]
GO
/****** Object:  ForeignKey [FK_dbo.UserGroups_dbo.Groups_GroupId]    Script Date: 11/11/2013 18:52:39 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.UserGroups_dbo.Groups_GroupId]') AND parent_object_id = OBJECT_ID(N'[dbo].[UserGroups]'))
ALTER TABLE [dbo].[UserGroups] DROP CONSTRAINT [FK_dbo.UserGroups_dbo.Groups_GroupId]
GO
/****** Object:  ForeignKey [FK_dbo.UserGroups_dbo.Users_UserId]    Script Date: 11/11/2013 18:52:39 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.UserGroups_dbo.Users_UserId]') AND parent_object_id = OBJECT_ID(N'[dbo].[UserGroups]'))
ALTER TABLE [dbo].[UserGroups] DROP CONSTRAINT [FK_dbo.UserGroups_dbo.Users_UserId]
GO
/****** Object:  ForeignKey [FK_dbo.UserLogins_dbo.Users_UserId]    Script Date: 11/11/2013 18:52:39 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.UserLogins_dbo.Users_UserId]') AND parent_object_id = OBJECT_ID(N'[dbo].[UserLogins]'))
ALTER TABLE [dbo].[UserLogins] DROP CONSTRAINT [FK_dbo.UserLogins_dbo.Users_UserId]
GO
/****** Object:  ForeignKey [FK_dbo.UserRoles_dbo.Roles_RoleId]    Script Date: 11/11/2013 18:52:39 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.UserRoles_dbo.Roles_RoleId]') AND parent_object_id = OBJECT_ID(N'[dbo].[UserRoles]'))
ALTER TABLE [dbo].[UserRoles] DROP CONSTRAINT [FK_dbo.UserRoles_dbo.Roles_RoleId]
GO
/****** Object:  ForeignKey [FK_dbo.UserRoles_dbo.Users_UserId]    Script Date: 11/11/2013 18:52:39 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.UserRoles_dbo.Users_UserId]') AND parent_object_id = OBJECT_ID(N'[dbo].[UserRoles]'))
ALTER TABLE [dbo].[UserRoles] DROP CONSTRAINT [FK_dbo.UserRoles_dbo.Users_UserId]
GO
/****** Object:  Table [dbo].[Bets]    Script Date: 11/11/2013 18:52:39 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.Bets_dbo.BetResults_BetResult_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[Bets]'))
ALTER TABLE [dbo].[Bets] DROP CONSTRAINT [FK_dbo.Bets_dbo.BetResults_BetResult_Id]
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.Bets_dbo.Events_Event_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[Bets]'))
ALTER TABLE [dbo].[Bets] DROP CONSTRAINT [FK_dbo.Bets_dbo.Events_Event_Id]
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.Bets_dbo.Users_User_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[Bets]'))
ALTER TABLE [dbo].[Bets] DROP CONSTRAINT [FK_dbo.Bets_dbo.Users_User_Id]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Bets]') AND type in (N'U'))
DROP TABLE [dbo].[Bets]
GO
/****** Object:  Table [dbo].[EventDescriptors]    Script Date: 11/11/2013 18:52:39 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.EventDescriptors_dbo.Events_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[EventDescriptors]'))
ALTER TABLE [dbo].[EventDescriptors] DROP CONSTRAINT [FK_dbo.EventDescriptors_dbo.Events_Id]
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.EventDescriptors_dbo.Teams_AwayTeam_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[EventDescriptors]'))
ALTER TABLE [dbo].[EventDescriptors] DROP CONSTRAINT [FK_dbo.EventDescriptors_dbo.Teams_AwayTeam_Id]
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.EventDescriptors_dbo.Teams_HomeTeam_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[EventDescriptors]'))
ALTER TABLE [dbo].[EventDescriptors] DROP CONSTRAINT [FK_dbo.EventDescriptors_dbo.Teams_HomeTeam_Id]
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.EventDescriptors_dbo.Teams_Team_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[EventDescriptors]'))
ALTER TABLE [dbo].[EventDescriptors] DROP CONSTRAINT [FK_dbo.EventDescriptors_dbo.Teams_Team_Id]
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.EventDescriptors_dbo.Teams_Team_Id1]') AND parent_object_id = OBJECT_ID(N'[dbo].[EventDescriptors]'))
ALTER TABLE [dbo].[EventDescriptors] DROP CONSTRAINT [FK_dbo.EventDescriptors_dbo.Teams_Team_Id1]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[EventDescriptors]') AND type in (N'U'))
DROP TABLE [dbo].[EventDescriptors]
GO
/****** Object:  Table [dbo].[GroupEvents]    Script Date: 11/11/2013 18:52:39 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.GroupEvents_dbo.Events_Event_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[GroupEvents]'))
ALTER TABLE [dbo].[GroupEvents] DROP CONSTRAINT [FK_dbo.GroupEvents_dbo.Events_Event_Id]
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.GroupEvents_dbo.Groups_Group_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[GroupEvents]'))
ALTER TABLE [dbo].[GroupEvents] DROP CONSTRAINT [FK_dbo.GroupEvents_dbo.Groups_Group_Id]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GroupEvents]') AND type in (N'U'))
DROP TABLE [dbo].[GroupEvents]
GO
/****** Object:  Table [dbo].[Results]    Script Date: 11/11/2013 18:52:39 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.Results_dbo.Events_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[Results]'))
ALTER TABLE [dbo].[Results] DROP CONSTRAINT [FK_dbo.Results_dbo.Events_Id]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Results]') AND type in (N'U'))
DROP TABLE [dbo].[Results]
GO
/****** Object:  Table [dbo].[UserGroups]    Script Date: 11/11/2013 18:52:39 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.UserGroups_dbo.Groups_GroupId]') AND parent_object_id = OBJECT_ID(N'[dbo].[UserGroups]'))
ALTER TABLE [dbo].[UserGroups] DROP CONSTRAINT [FK_dbo.UserGroups_dbo.Groups_GroupId]
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.UserGroups_dbo.Users_UserId]') AND parent_object_id = OBJECT_ID(N'[dbo].[UserGroups]'))
ALTER TABLE [dbo].[UserGroups] DROP CONSTRAINT [FK_dbo.UserGroups_dbo.Users_UserId]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UserGroups]') AND type in (N'U'))
DROP TABLE [dbo].[UserGroups]
GO
/****** Object:  Table [dbo].[BetResults]    Script Date: 11/11/2013 18:52:38 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.BetResults_dbo.Events_Event_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[BetResults]'))
ALTER TABLE [dbo].[BetResults] DROP CONSTRAINT [FK_dbo.BetResults_dbo.Events_Event_Id]
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.BetResults_dbo.Users_User_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[BetResults]'))
ALTER TABLE [dbo].[BetResults] DROP CONSTRAINT [FK_dbo.BetResults_dbo.Users_User_Id]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[BetResults]') AND type in (N'U'))
DROP TABLE [dbo].[BetResults]
GO
/****** Object:  Table [dbo].[UserClaims]    Script Date: 11/11/2013 18:52:39 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.UserClaims_dbo.Users_User_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[UserClaims]'))
ALTER TABLE [dbo].[UserClaims] DROP CONSTRAINT [FK_dbo.UserClaims_dbo.Users_User_Id]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UserClaims]') AND type in (N'U'))
DROP TABLE [dbo].[UserClaims]
GO
/****** Object:  Table [dbo].[UserLogins]    Script Date: 11/11/2013 18:52:39 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.UserLogins_dbo.Users_UserId]') AND parent_object_id = OBJECT_ID(N'[dbo].[UserLogins]'))
ALTER TABLE [dbo].[UserLogins] DROP CONSTRAINT [FK_dbo.UserLogins_dbo.Users_UserId]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UserLogins]') AND type in (N'U'))
DROP TABLE [dbo].[UserLogins]
GO
/****** Object:  Table [dbo].[UserRoles]    Script Date: 11/11/2013 18:52:39 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.UserRoles_dbo.Roles_RoleId]') AND parent_object_id = OBJECT_ID(N'[dbo].[UserRoles]'))
ALTER TABLE [dbo].[UserRoles] DROP CONSTRAINT [FK_dbo.UserRoles_dbo.Roles_RoleId]
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.UserRoles_dbo.Users_UserId]') AND parent_object_id = OBJECT_ID(N'[dbo].[UserRoles]'))
ALTER TABLE [dbo].[UserRoles] DROP CONSTRAINT [FK_dbo.UserRoles_dbo.Users_UserId]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UserRoles]') AND type in (N'U'))
DROP TABLE [dbo].[UserRoles]
GO
/****** Object:  Table [dbo].[Groups]    Script Date: 11/11/2013 18:52:39 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.Groups_dbo.Users_Creator_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[Groups]'))
ALTER TABLE [dbo].[Groups] DROP CONSTRAINT [FK_dbo.Groups_dbo.Users_Creator_Id]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Groups]') AND type in (N'U'))
DROP TABLE [dbo].[Groups]
GO
/****** Object:  Table [dbo].[Logs]    Script Date: 11/11/2013 18:52:39 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.Logs_dbo.Users_User_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[Logs]'))
ALTER TABLE [dbo].[Logs] DROP CONSTRAINT [FK_dbo.Logs_dbo.Users_User_Id]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Logs]') AND type in (N'U'))
DROP TABLE [dbo].[Logs]
GO
/****** Object:  Table [dbo].[Events]    Script Date: 11/11/2013 18:52:39 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.Events_dbo.Users_Creator_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[Events]'))
ALTER TABLE [dbo].[Events] DROP CONSTRAINT [FK_dbo.Events_dbo.Users_Creator_Id]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Events]') AND type in (N'U'))
DROP TABLE [dbo].[Events]
GO
/****** Object:  Table [dbo].[Roles]    Script Date: 11/11/2013 18:52:39 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Roles]') AND type in (N'U'))
DROP TABLE [dbo].[Roles]
GO
/****** Object:  Table [dbo].[Teams]    Script Date: 11/11/2013 18:52:39 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Teams]') AND type in (N'U'))
DROP TABLE [dbo].[Teams]
GO
/****** Object:  Table [dbo].[Users]    Script Date: 11/11/2013 18:52:40 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Users]') AND type in (N'U'))
DROP TABLE [dbo].[Users]
GO
/****** Object:  Table [dbo].[Users]    Script Date: 11/11/2013 18:52:40 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Users]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Users](
	[Id] [nvarchar](128) NOT NULL,
	[UserName] [nvarchar](max) NULL,
	[PasswordHash] [nvarchar](max) NULL,
	[SecurityStamp] [nvarchar](max) NULL,
	[Discriminator] [nvarchar](128) NOT NULL,
 CONSTRAINT [PK_dbo.Users] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[Teams]    Script Date: 11/11/2013 18:52:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Teams]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Teams](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](max) NULL,
	[ShortName] [nvarchar](max) NULL,
	[LogoUrl] [nvarchar](max) NULL,
	[Description] [nvarchar](max) NULL,
 CONSTRAINT [PK_dbo.Teams] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[Roles]    Script Date: 11/11/2013 18:52:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Roles]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Roles](
	[Id] [nvarchar](128) NOT NULL,
	[Name] [nvarchar](max) NOT NULL,
 CONSTRAINT [PK_dbo.Roles] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[Events]    Script Date: 11/11/2013 18:52:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Events]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Events](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[EventDate] [datetime] NOT NULL,
	[BetStartAt] [datetime] NOT NULL,
	[BetEndAt] [datetime] NOT NULL,
	[Available] [bit] NOT NULL,
	[Name] [nvarchar](max) NULL,
	[ShortName] [nvarchar](max) NULL,
	[Status] [int] NOT NULL,
	[Creator_Id] [nvarchar](128) NULL,
 CONSTRAINT [PK_dbo.Events] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[Logs]    Script Date: 11/11/2013 18:52:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Logs]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Logs](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[At] [datetime] NOT NULL,
	[ReferredType] [nvarchar](max) NULL,
	[ReferredId] [nvarchar](max) NULL,
	[Action] [nvarchar](max) NULL,
	[OldValue] [nvarchar](max) NULL,
	[NewValue] [nvarchar](max) NULL,
	[User_Id] [nvarchar](128) NULL,
 CONSTRAINT [PK_dbo.Logs] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[Groups]    Script Date: 11/11/2013 18:52:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Groups]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Groups](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](max) NULL,
	[ShortName] [nvarchar](max) NULL,
	[Description] [nvarchar](max) NULL,
	[Creator_Id] [nvarchar](128) NULL,
 CONSTRAINT [PK_dbo.Groups] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[UserRoles]    Script Date: 11/11/2013 18:52:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UserRoles]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[UserRoles](
	[UserId] [nvarchar](128) NOT NULL,
	[RoleId] [nvarchar](128) NOT NULL,
 CONSTRAINT [PK_dbo.UserRoles] PRIMARY KEY CLUSTERED 
(
	[UserId] ASC,
	[RoleId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[UserLogins]    Script Date: 11/11/2013 18:52:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UserLogins]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[UserLogins](
	[UserId] [nvarchar](128) NOT NULL,
	[LoginProvider] [nvarchar](128) NOT NULL,
	[ProviderKey] [nvarchar](128) NOT NULL,
 CONSTRAINT [PK_dbo.UserLogins] PRIMARY KEY CLUSTERED 
(
	[UserId] ASC,
	[LoginProvider] ASC,
	[ProviderKey] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[UserClaims]    Script Date: 11/11/2013 18:52:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UserClaims]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[UserClaims](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[ClaimType] [nvarchar](max) NULL,
	[ClaimValue] [nvarchar](max) NULL,
	[User_Id] [nvarchar](128) NOT NULL,
 CONSTRAINT [PK_dbo.UserClaims] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[BetResults]    Script Date: 11/11/2013 18:52:38 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[BetResults]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[BetResults](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[PointsEarned] [int] NOT NULL,
	[CheckedAt] [nvarchar](max) NULL,
	[Event_Id] [int] NULL,
	[User_Id] [nvarchar](128) NOT NULL,
 CONSTRAINT [PK_dbo.BetResults] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[UserGroups]    Script Date: 11/11/2013 18:52:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UserGroups]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[UserGroups](
	[UserId] [nvarchar](128) NOT NULL,
	[GroupId] [int] NOT NULL,
 CONSTRAINT [PK_dbo.UserGroups] PRIMARY KEY CLUSTERED 
(
	[UserId] ASC,
	[GroupId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[Results]    Script Date: 11/11/2013 18:52:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Results]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Results](
	[Id] [int] NOT NULL,
	[HomeResult] [int] NOT NULL,
	[AwayResult] [int] NOT NULL,
	[AddedAt] [datetime] NOT NULL,
 CONSTRAINT [PK_dbo.Results] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[GroupEvents]    Script Date: 11/11/2013 18:52:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GroupEvents]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[GroupEvents](
	[Group_Id] [int] NOT NULL,
	[Event_Id] [int] NOT NULL,
 CONSTRAINT [PK_dbo.GroupEvents] PRIMARY KEY CLUSTERED 
(
	[Group_Id] ASC,
	[Event_Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[EventDescriptors]    Script Date: 11/11/2013 18:52:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[EventDescriptors]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[EventDescriptors](
	[Id] [int] NOT NULL,
	[Name] [nvarchar](max) NULL,
	[Description] [nvarchar](max) NULL,
	[EventInfo] [nvarchar](max) NULL,
	[Team_Id] [int] NULL,
	[Team_Id1] [int] NULL,
	[AwayTeam_Id] [int] NULL,
	[HomeTeam_Id] [int] NULL,
 CONSTRAINT [PK_dbo.EventDescriptors] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[Bets]    Script Date: 11/11/2013 18:52:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Bets]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Bets](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[HomeBet] [int] NOT NULL,
	[AwayBet] [int] NOT NULL,
	[BetAt] [datetime] NOT NULL,
	[Checked] [bit] NOT NULL,
	[BetResult_Id] [int] NULL,
	[Event_Id] [int] NULL,
	[User_Id] [nvarchar](128) NOT NULL,
 CONSTRAINT [PK_dbo.Bets] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  ForeignKey [FK_dbo.BetResults_dbo.Events_Event_Id]    Script Date: 11/11/2013 18:52:38 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.BetResults_dbo.Events_Event_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[BetResults]'))
ALTER TABLE [dbo].[BetResults]  WITH CHECK ADD  CONSTRAINT [FK_dbo.BetResults_dbo.Events_Event_Id] FOREIGN KEY([Event_Id])
REFERENCES [dbo].[Events] ([Id])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.BetResults_dbo.Events_Event_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[BetResults]'))
ALTER TABLE [dbo].[BetResults] CHECK CONSTRAINT [FK_dbo.BetResults_dbo.Events_Event_Id]
GO
/****** Object:  ForeignKey [FK_dbo.BetResults_dbo.Users_User_Id]    Script Date: 11/11/2013 18:52:38 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.BetResults_dbo.Users_User_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[BetResults]'))
ALTER TABLE [dbo].[BetResults]  WITH CHECK ADD  CONSTRAINT [FK_dbo.BetResults_dbo.Users_User_Id] FOREIGN KEY([User_Id])
REFERENCES [dbo].[Users] ([Id])
ON DELETE CASCADE
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.BetResults_dbo.Users_User_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[BetResults]'))
ALTER TABLE [dbo].[BetResults] CHECK CONSTRAINT [FK_dbo.BetResults_dbo.Users_User_Id]
GO
/****** Object:  ForeignKey [FK_dbo.Bets_dbo.BetResults_BetResult_Id]    Script Date: 11/11/2013 18:52:39 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.Bets_dbo.BetResults_BetResult_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[Bets]'))
ALTER TABLE [dbo].[Bets]  WITH CHECK ADD  CONSTRAINT [FK_dbo.Bets_dbo.BetResults_BetResult_Id] FOREIGN KEY([BetResult_Id])
REFERENCES [dbo].[BetResults] ([Id])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.Bets_dbo.BetResults_BetResult_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[Bets]'))
ALTER TABLE [dbo].[Bets] CHECK CONSTRAINT [FK_dbo.Bets_dbo.BetResults_BetResult_Id]
GO
/****** Object:  ForeignKey [FK_dbo.Bets_dbo.Events_Event_Id]    Script Date: 11/11/2013 18:52:39 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.Bets_dbo.Events_Event_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[Bets]'))
ALTER TABLE [dbo].[Bets]  WITH CHECK ADD  CONSTRAINT [FK_dbo.Bets_dbo.Events_Event_Id] FOREIGN KEY([Event_Id])
REFERENCES [dbo].[Events] ([Id])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.Bets_dbo.Events_Event_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[Bets]'))
ALTER TABLE [dbo].[Bets] CHECK CONSTRAINT [FK_dbo.Bets_dbo.Events_Event_Id]
GO
/****** Object:  ForeignKey [FK_dbo.Bets_dbo.Users_User_Id]    Script Date: 11/11/2013 18:52:39 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.Bets_dbo.Users_User_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[Bets]'))
ALTER TABLE [dbo].[Bets]  WITH CHECK ADD  CONSTRAINT [FK_dbo.Bets_dbo.Users_User_Id] FOREIGN KEY([User_Id])
REFERENCES [dbo].[Users] ([Id])
ON DELETE CASCADE
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.Bets_dbo.Users_User_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[Bets]'))
ALTER TABLE [dbo].[Bets] CHECK CONSTRAINT [FK_dbo.Bets_dbo.Users_User_Id]
GO
/****** Object:  ForeignKey [FK_dbo.EventDescriptors_dbo.Events_Id]    Script Date: 11/11/2013 18:52:39 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.EventDescriptors_dbo.Events_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[EventDescriptors]'))
ALTER TABLE [dbo].[EventDescriptors]  WITH CHECK ADD  CONSTRAINT [FK_dbo.EventDescriptors_dbo.Events_Id] FOREIGN KEY([Id])
REFERENCES [dbo].[Events] ([Id])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.EventDescriptors_dbo.Events_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[EventDescriptors]'))
ALTER TABLE [dbo].[EventDescriptors] CHECK CONSTRAINT [FK_dbo.EventDescriptors_dbo.Events_Id]
GO
/****** Object:  ForeignKey [FK_dbo.EventDescriptors_dbo.Teams_AwayTeam_Id]    Script Date: 11/11/2013 18:52:39 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.EventDescriptors_dbo.Teams_AwayTeam_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[EventDescriptors]'))
ALTER TABLE [dbo].[EventDescriptors]  WITH CHECK ADD  CONSTRAINT [FK_dbo.EventDescriptors_dbo.Teams_AwayTeam_Id] FOREIGN KEY([AwayTeam_Id])
REFERENCES [dbo].[Teams] ([Id])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.EventDescriptors_dbo.Teams_AwayTeam_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[EventDescriptors]'))
ALTER TABLE [dbo].[EventDescriptors] CHECK CONSTRAINT [FK_dbo.EventDescriptors_dbo.Teams_AwayTeam_Id]
GO
/****** Object:  ForeignKey [FK_dbo.EventDescriptors_dbo.Teams_HomeTeam_Id]    Script Date: 11/11/2013 18:52:39 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.EventDescriptors_dbo.Teams_HomeTeam_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[EventDescriptors]'))
ALTER TABLE [dbo].[EventDescriptors]  WITH CHECK ADD  CONSTRAINT [FK_dbo.EventDescriptors_dbo.Teams_HomeTeam_Id] FOREIGN KEY([HomeTeam_Id])
REFERENCES [dbo].[Teams] ([Id])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.EventDescriptors_dbo.Teams_HomeTeam_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[EventDescriptors]'))
ALTER TABLE [dbo].[EventDescriptors] CHECK CONSTRAINT [FK_dbo.EventDescriptors_dbo.Teams_HomeTeam_Id]
GO
/****** Object:  ForeignKey [FK_dbo.EventDescriptors_dbo.Teams_Team_Id]    Script Date: 11/11/2013 18:52:39 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.EventDescriptors_dbo.Teams_Team_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[EventDescriptors]'))
ALTER TABLE [dbo].[EventDescriptors]  WITH CHECK ADD  CONSTRAINT [FK_dbo.EventDescriptors_dbo.Teams_Team_Id] FOREIGN KEY([Team_Id])
REFERENCES [dbo].[Teams] ([Id])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.EventDescriptors_dbo.Teams_Team_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[EventDescriptors]'))
ALTER TABLE [dbo].[EventDescriptors] CHECK CONSTRAINT [FK_dbo.EventDescriptors_dbo.Teams_Team_Id]
GO
/****** Object:  ForeignKey [FK_dbo.EventDescriptors_dbo.Teams_Team_Id1]    Script Date: 11/11/2013 18:52:39 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.EventDescriptors_dbo.Teams_Team_Id1]') AND parent_object_id = OBJECT_ID(N'[dbo].[EventDescriptors]'))
ALTER TABLE [dbo].[EventDescriptors]  WITH CHECK ADD  CONSTRAINT [FK_dbo.EventDescriptors_dbo.Teams_Team_Id1] FOREIGN KEY([Team_Id1])
REFERENCES [dbo].[Teams] ([Id])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.EventDescriptors_dbo.Teams_Team_Id1]') AND parent_object_id = OBJECT_ID(N'[dbo].[EventDescriptors]'))
ALTER TABLE [dbo].[EventDescriptors] CHECK CONSTRAINT [FK_dbo.EventDescriptors_dbo.Teams_Team_Id1]
GO
/****** Object:  ForeignKey [FK_dbo.Events_dbo.Users_Creator_Id]    Script Date: 11/11/2013 18:52:39 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.Events_dbo.Users_Creator_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[Events]'))
ALTER TABLE [dbo].[Events]  WITH CHECK ADD  CONSTRAINT [FK_dbo.Events_dbo.Users_Creator_Id] FOREIGN KEY([Creator_Id])
REFERENCES [dbo].[Users] ([Id])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.Events_dbo.Users_Creator_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[Events]'))
ALTER TABLE [dbo].[Events] CHECK CONSTRAINT [FK_dbo.Events_dbo.Users_Creator_Id]
GO
/****** Object:  ForeignKey [FK_dbo.GroupEvents_dbo.Events_Event_Id]    Script Date: 11/11/2013 18:52:39 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.GroupEvents_dbo.Events_Event_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[GroupEvents]'))
ALTER TABLE [dbo].[GroupEvents]  WITH CHECK ADD  CONSTRAINT [FK_dbo.GroupEvents_dbo.Events_Event_Id] FOREIGN KEY([Event_Id])
REFERENCES [dbo].[Events] ([Id])
ON DELETE CASCADE
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.GroupEvents_dbo.Events_Event_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[GroupEvents]'))
ALTER TABLE [dbo].[GroupEvents] CHECK CONSTRAINT [FK_dbo.GroupEvents_dbo.Events_Event_Id]
GO
/****** Object:  ForeignKey [FK_dbo.GroupEvents_dbo.Groups_Group_Id]    Script Date: 11/11/2013 18:52:39 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.GroupEvents_dbo.Groups_Group_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[GroupEvents]'))
ALTER TABLE [dbo].[GroupEvents]  WITH CHECK ADD  CONSTRAINT [FK_dbo.GroupEvents_dbo.Groups_Group_Id] FOREIGN KEY([Group_Id])
REFERENCES [dbo].[Groups] ([Id])
ON DELETE CASCADE
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.GroupEvents_dbo.Groups_Group_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[GroupEvents]'))
ALTER TABLE [dbo].[GroupEvents] CHECK CONSTRAINT [FK_dbo.GroupEvents_dbo.Groups_Group_Id]
GO
/****** Object:  ForeignKey [FK_dbo.Groups_dbo.Users_Creator_Id]    Script Date: 11/11/2013 18:52:39 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.Groups_dbo.Users_Creator_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[Groups]'))
ALTER TABLE [dbo].[Groups]  WITH CHECK ADD  CONSTRAINT [FK_dbo.Groups_dbo.Users_Creator_Id] FOREIGN KEY([Creator_Id])
REFERENCES [dbo].[Users] ([Id])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.Groups_dbo.Users_Creator_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[Groups]'))
ALTER TABLE [dbo].[Groups] CHECK CONSTRAINT [FK_dbo.Groups_dbo.Users_Creator_Id]
GO
/****** Object:  ForeignKey [FK_dbo.Logs_dbo.Users_User_Id]    Script Date: 11/11/2013 18:52:39 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.Logs_dbo.Users_User_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[Logs]'))
ALTER TABLE [dbo].[Logs]  WITH CHECK ADD  CONSTRAINT [FK_dbo.Logs_dbo.Users_User_Id] FOREIGN KEY([User_Id])
REFERENCES [dbo].[Users] ([Id])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.Logs_dbo.Users_User_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[Logs]'))
ALTER TABLE [dbo].[Logs] CHECK CONSTRAINT [FK_dbo.Logs_dbo.Users_User_Id]
GO
/****** Object:  ForeignKey [FK_dbo.Results_dbo.Events_Id]    Script Date: 11/11/2013 18:52:39 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.Results_dbo.Events_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[Results]'))
ALTER TABLE [dbo].[Results]  WITH CHECK ADD  CONSTRAINT [FK_dbo.Results_dbo.Events_Id] FOREIGN KEY([Id])
REFERENCES [dbo].[Events] ([Id])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.Results_dbo.Events_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[Results]'))
ALTER TABLE [dbo].[Results] CHECK CONSTRAINT [FK_dbo.Results_dbo.Events_Id]
GO
/****** Object:  ForeignKey [FK_dbo.UserClaims_dbo.Users_User_Id]    Script Date: 11/11/2013 18:52:39 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.UserClaims_dbo.Users_User_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[UserClaims]'))
ALTER TABLE [dbo].[UserClaims]  WITH CHECK ADD  CONSTRAINT [FK_dbo.UserClaims_dbo.Users_User_Id] FOREIGN KEY([User_Id])
REFERENCES [dbo].[Users] ([Id])
ON DELETE CASCADE
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.UserClaims_dbo.Users_User_Id]') AND parent_object_id = OBJECT_ID(N'[dbo].[UserClaims]'))
ALTER TABLE [dbo].[UserClaims] CHECK CONSTRAINT [FK_dbo.UserClaims_dbo.Users_User_Id]
GO
/****** Object:  ForeignKey [FK_dbo.UserGroups_dbo.Groups_GroupId]    Script Date: 11/11/2013 18:52:39 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.UserGroups_dbo.Groups_GroupId]') AND parent_object_id = OBJECT_ID(N'[dbo].[UserGroups]'))
ALTER TABLE [dbo].[UserGroups]  WITH CHECK ADD  CONSTRAINT [FK_dbo.UserGroups_dbo.Groups_GroupId] FOREIGN KEY([GroupId])
REFERENCES [dbo].[Groups] ([Id])
ON DELETE CASCADE
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.UserGroups_dbo.Groups_GroupId]') AND parent_object_id = OBJECT_ID(N'[dbo].[UserGroups]'))
ALTER TABLE [dbo].[UserGroups] CHECK CONSTRAINT [FK_dbo.UserGroups_dbo.Groups_GroupId]
GO
/****** Object:  ForeignKey [FK_dbo.UserGroups_dbo.Users_UserId]    Script Date: 11/11/2013 18:52:39 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.UserGroups_dbo.Users_UserId]') AND parent_object_id = OBJECT_ID(N'[dbo].[UserGroups]'))
ALTER TABLE [dbo].[UserGroups]  WITH CHECK ADD  CONSTRAINT [FK_dbo.UserGroups_dbo.Users_UserId] FOREIGN KEY([UserId])
REFERENCES [dbo].[Users] ([Id])
ON DELETE CASCADE
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.UserGroups_dbo.Users_UserId]') AND parent_object_id = OBJECT_ID(N'[dbo].[UserGroups]'))
ALTER TABLE [dbo].[UserGroups] CHECK CONSTRAINT [FK_dbo.UserGroups_dbo.Users_UserId]
GO
/****** Object:  ForeignKey [FK_dbo.UserLogins_dbo.Users_UserId]    Script Date: 11/11/2013 18:52:39 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.UserLogins_dbo.Users_UserId]') AND parent_object_id = OBJECT_ID(N'[dbo].[UserLogins]'))
ALTER TABLE [dbo].[UserLogins]  WITH CHECK ADD  CONSTRAINT [FK_dbo.UserLogins_dbo.Users_UserId] FOREIGN KEY([UserId])
REFERENCES [dbo].[Users] ([Id])
ON DELETE CASCADE
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.UserLogins_dbo.Users_UserId]') AND parent_object_id = OBJECT_ID(N'[dbo].[UserLogins]'))
ALTER TABLE [dbo].[UserLogins] CHECK CONSTRAINT [FK_dbo.UserLogins_dbo.Users_UserId]
GO
/****** Object:  ForeignKey [FK_dbo.UserRoles_dbo.Roles_RoleId]    Script Date: 11/11/2013 18:52:39 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.UserRoles_dbo.Roles_RoleId]') AND parent_object_id = OBJECT_ID(N'[dbo].[UserRoles]'))
ALTER TABLE [dbo].[UserRoles]  WITH CHECK ADD  CONSTRAINT [FK_dbo.UserRoles_dbo.Roles_RoleId] FOREIGN KEY([RoleId])
REFERENCES [dbo].[Roles] ([Id])
ON DELETE CASCADE
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.UserRoles_dbo.Roles_RoleId]') AND parent_object_id = OBJECT_ID(N'[dbo].[UserRoles]'))
ALTER TABLE [dbo].[UserRoles] CHECK CONSTRAINT [FK_dbo.UserRoles_dbo.Roles_RoleId]
GO
/****** Object:  ForeignKey [FK_dbo.UserRoles_dbo.Users_UserId]    Script Date: 11/11/2013 18:52:39 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.UserRoles_dbo.Users_UserId]') AND parent_object_id = OBJECT_ID(N'[dbo].[UserRoles]'))
ALTER TABLE [dbo].[UserRoles]  WITH CHECK ADD  CONSTRAINT [FK_dbo.UserRoles_dbo.Users_UserId] FOREIGN KEY([UserId])
REFERENCES [dbo].[Users] ([Id])
ON DELETE CASCADE
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_dbo.UserRoles_dbo.Users_UserId]') AND parent_object_id = OBJECT_ID(N'[dbo].[UserRoles]'))
ALTER TABLE [dbo].[UserRoles] CHECK CONSTRAINT [FK_dbo.UserRoles_dbo.Users_UserId]
GO
